<template>
	<div v-loading="loading">
		<el-form :inline="true" :model="queryForm" size="mini" >
			<el-form-item>
				<el-col :span="10">
					<el-date-picker format="yyyy-MM" type="month" value-format="yyyy-MM" placeholder="开始月份" v-model="queryForm.startMonth" style="width: 150px;"></el-date-picker>
				</el-col>
				<el-col class="line" :span="2">-</el-col>
				<el-col :span="10">
					<el-date-picker format="yyyy-MM" type="month" value-format="yyyy-MM" placeholder="结束月份" v-model="queryForm.endMonth" style="width: 150px;"></el-date-picker>
				</el-col>
				
			</el-form-item>
			<el-form-item>
				<el-input v-model="queryForm.customerName" placeholder="客户"></el-input>
			</el-form-item>
		  
		  <el-form-item>
		    <el-button type="primary" @click="query">查询</el-button>
		  </el-form-item>
		  <el-form-item>
		    <el-button type="primary" @click="exportExcel">导出</el-button>
		  </el-form-item>
		  
		</el-form>
		
		<el-form :inline="true" :model="calculateForm" size="mini">
			<el-form-item>
				<el-col :span="10">
					<el-date-picker format="yyyy-MM" type="month" value-format="yyyy-MM" placeholder="开始月份" v-model="calculateForm.startMonth" style="width: 150px;"></el-date-picker>
				</el-col>
				
			</el-form-item>
		  <el-form-item>
		    <el-button type="primary" @click="calculateCustomBalanceFunc">计算开始月份到上个月的月度余额</el-button>
		  </el-form-item>
		  <el-form-item>
		    <el-button type="primary" @click="calculateBalanceFunc">计算上个月的月度余额</el-button>
		  </el-form-item>
		</el-form>
		<!--结转-->
		<el-form :inline="true" :model="carryForm" size="mini">
			<el-form-item>
				<el-col :span="10">
					<el-date-picker format="yyyy" type="year" value-format="yyyy" placeholder="结转年份" v-model="carryForm.carryYear" style="width: 150px;"></el-date-picker>
				</el-col>
				
			</el-form-item>
		  <el-form-item>
		    <el-button type="primary" @click="carryForwardFunc">结转</el-button>
		  </el-form-item>
		</el-form>
		
		
		<el-table
			:header-cell-style="{background:'#F5F5F5',color:'#606266'}"
			size='mini' 
		   :data="tableData"
		   :max-height="tableHeight"
		   border
		   style="width: 100%">
		   <el-table-column
		     prop="month"
		     label="月份">
		   </el-table-column>
		   <el-table-column
		     prop="customerName"
		     label="客户名称">
		   </el-table-column>
		   <el-table-column
		     prop="monthlyBalance"
		     label="月度余额">
		   </el-table-column>
		   <el-table-column
		     prop="remark"
		     label="备注">
		   </el-table-column>
		   <el-table-column
		     prop="lastUpdateTime"
		     label="最细更新时间">
		   </el-table-column>
		 </el-table>
		
	</div>
</template>

<script>
	import request from '../../../api/request.js'
	import { ObjToFormData } from '../../../util/commonUtil.js';
	import {PRE_URL}from '../../../util/constants.js'
	import RoutePaths from '../../../util/constants.js'  //引用模块进来
	
	export default{
		name:RoutePaths.ROUTE_RPT_MONTHLYBALANCE_NAME,
		data() {
		  return {
			//查询时loading
			loading:false,
			queryForm: {
				startMonth: '',
				endMonth:'',
				customerName:''
			},
			//自定义时间段  计算月份余额的 form
			calculateForm: {
				startMonth: ''
			},
			//结转的 form
			carryForm: {
				carryYear: ''
			},
			
			dialogVisible:false,
			tableHeight: window.innerHeight - 300,
			tableData: []
		  }
		},
		mounted () {

		},
		methods:{
			exportExcelForTravel(){
				
			},
			//查询
			query(){
				var form  = ObjToFormData(this.queryForm);
				var me = this;
				request.post('/api/rpt/listMonthlyBalanceRPT',
					form).then(
					response => {
						const result = response.data;
						const resultCount = response.count;
				
						me.commonUtil.showMessage(response.code,response.message);
						
						//给 数据显示赋值
						this.tableData = result;
					})
			},
			// 计算 余额
			calculateBalanceFunc(){
				this.loading = true;
				var me = this;
				request.post('/api/rpt/calculateBalance').then(
					response => {
						me.commonUtil.showMessage(response.code,response.message);
						this.loading = false;
					}).catch(err=>{
						this.loading = false
					})
				
			},
			// 时间跨度 计算余额
			calculateCustomBalanceFunc(){
				var form  = ObjToFormData(this.calculateForm);
				var me = this;
				this.loading = true;
				request.post('/api/rpt/calculateCustomBalance',
					form).then(
					response => {
						me.commonUtil.showMessage(response.code,response.message);
						this.loading = false;
					}).catch(err=>{
						this.loading = false
					})
										
			},
			//结转 
			carryForwardFunc(){
				var form  = ObjToFormData(this.carryForm);
				var me = this;
				this.loading = true;
				request.post('/api/rpt/carryForward',
					form).then(
					response => {
						me.commonUtil.showMessage(response.code,response.message);
						this.loading = false;
					}).catch(err=>{
						this.loading = false
					})
			}
		}
	}
</script>

<style>
</style>
